import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.IconButton
import androidx.compose.material.Text
import androidx.compose.ui.graphics.Color

// 替换为你的实际包名
import com.yourpackage.name.R

@Composable
fun LanguageSwitcherScreen() {
    var currentLanguage by remember { mutableStateOf("zh") }
    var message by remember { mutableStateOf("你好，世界！") }

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        Text(
            text = message,
            fontSize = 24.sp,
            modifier = Modifier.padding(20.dp),
            color = Color.Black
        )

        Row(
            modifier = Modifier.padding(10.dp),
            horizontalArrangement = Arrangement.spacedBy(16.dp)
        ) {
            // 中国国旗 - flag.jpg
            IconButton(onClick = {
                currentLanguage = "zh"
                message = "你好，世界！"
            }) {
                Image(
                    painter = painterResource(id = R.drawable.flag),
                    contentDescription = "切换到中文",
                    modifier = Modifier.size(48.dp)
                )
            }

            // 美国国旗 - flag.jpg1
            IconButton(onClick = {
                currentLanguage = "en"
                message = "Hello, World!"
            }) {
                Image(
                    painter = painterResource(id = R.drawable.flag_jpg1),
                    contentDescription = "切换到英文",
                    modifier = Modifier.size(48.dp)
                )
            }

            // 日本国旗 - flag.jpg2
            IconButton(onClick = {
                currentLanguage = "ja"
                message = "こんにちは、世界！"
            }) {
                Image(
                    painter = painterResource(id = R.drawable.flag_jpg2),
                    contentDescription = "切换到日文",
                    modifier = Modifier.size(48.dp)
                )
            }
        }

        Text(
            text = "当前语言: ${getLanguageName(currentLanguage)}",
            fontSize = 16.sp,
            modifier = Modifier.padding(top = 20.dp),
            color = Color.Gray
        )
    }
}

private fun getLanguageName(code: String): String {
    return when(code) {
        "zh" -> "中文"
        "en" -> "英文"
        "ja" -> "日文"
        else -> "未知"
    }
}

@Preview(showBackground = true)
@Composable
fun LanguageSwitcherPreview() {
    LanguageSwitcherScreen()
}
